/*
 * keyboardInput.c
 *
 *  Created on: Mar 14, 2013
 *      Author: abrahamsantini
 */
#include "keyboardInput.h"
#include <stdlib.h>
#include "cpu.h"
#include <string.h>
#include <sys/time.h>
#include <stdio.h>
#include <pthread.h>
#include <errno.h>

int init_keyboardInput(keyboardInput_t *kb) {
	int ret = pthread_mutex_init(&kb->mutex, NULL);
		if (ret !=0){
			return ret;
		}
		ret = pthread_cond_init(&kb->cond, NULL);
		return ret;
	}


void start_KBInput(CPU* cpu) {
	keyboardInput_t kb;
	init_keyboardInput(&kb);

	int bytes_read;
	int nbytes = 1;
	char *my_input;
	int counter;

	my_input = (char*) malloc (nbytes);

	printf("Keyboard interrupt handler ready");
	while(1) {
		fflush(stdout);
		char* myvariable = malloc(40);
		scanf("%s",myvariable);
		if (strcmp(myvariable, "") != 0){
			keyboardInterrupt(cpu, myvariable);
			myvariable = "";
		}
	}
}


void create_keyboard_input_thread(CPU* cpu){
	pthread_t(thread);
	int ret = pthread_create(&thread, NULL, start_KBInput, NULL);

}
